<?PHP
// vim: set expandtab tabstop=4 shiftwidth=4:
// +----------------------------------------------------------------------+
// | SAPID: XML Sapiens Engine Demonstrator                               |
// +----------------------------------------------------------------------+
// | Author:  Max Baryshnikov aka Mephius <mb@rg.by>	                  |
// | Copyright (c) 2004 Max Baryshnikov                                   |
// | http://sapid.sourceforge.net	                                      |
// +----------------------------------------------------------------------+
// | This source file is free software; you can redistribute it and/or    |
// | modify it under the terms of the GNU Lesser General Public           |
// | License as published by the Free Software Foundation; either         |
// | version 2.1 of the License, or (at your option) any later version.   |
// |                                                                      |
// | This source file is distributed in the hope that it will be useful,  |
// | but WITHOUT ANY WARRANTY; without even the implied warranty of       |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU    |
// | Lesser General Public License for more details.                      |
// +----------------------------------------------------------------------+
// $Release: 13.11.04 (dd/mm/yy) $
// $Id: preview.php,v 1.4 2005/12/01 09:35:15 mephius Exp $

session_start();
if(!isset($_SESSION["user"]["LOGIN"]) or $_SESSION["user"]["NOLOGIN"]!="") die();


include_once("../../etc/rc.conf.php");
if($language=="ru" or $language=="en") $default_language=$language;
if(!$default_language) $default_language="ru";


$root_path = preg_replace("/usr\/system\/preview\.php$/is", "", $_SERVER["SCRIPT_FILENAME"]);
include_once('../../lang/'.$default_language.'.inc.php');

$template=preg_replace("/\//", "", $_GET["name"]);
$fp=@fopen(ROOT_PATH . "usr/templates/" . $template, "r");
if($fp){
	$size=filesize(ROOT_PATH . "usr/templates/" . $template);
	$data=fread($fp, $size);
	fclose($fp);
	echo preg_replace("/<sapi:apply\s+name=\"([a-zA-Z\.\d_\-]*)\"(.*?)\/>/", "<div style=\"border: 1px solid gray; padding: 3px;\">\\1</div>", $data);
}else echo "Sory, file can't be previewed";
?>